﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;

namespace TestConsole
{
    class Program
    {
        static void Main(string[] args)
        {
            Int32 length = 10000000;
            Task[] tasks1 = new Task[length], tasks2 = new Task[length];
            for (int i = 0; i < length; i++)
            {
                tasks1[i] = new Task(() => { });
                tasks2[i] = new Task(() => { });
            }

            Stopwatch sw = new Stopwatch();
            sw.Start();
            foreach (Task task in tasks1)
            {
                task.Start();
            }
            Task.WaitAll();
            sw.Stop();
            Console.WriteLine("普通耗时：{0}", sw.Elapsed);

            sw.Restart();
            Parallel.ForEach(tasks2, t =>
            {
                t.Start();
            });
            Task.WaitAll();
            sw.Stop();
            Console.WriteLine("并行耗时：{0}", sw.Elapsed);
            Console.ReadLine();
        }
    }
}
